package com.fenghuajueli.module_user.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.WindowManager;

import com.blankj.utilcode.util.SizeUtils;
import com.fenghuajueli.module_user.R;
import com.fenghuajueli.module_user.databinding.DialogDeleteUserBinding;

public class DeleteUserDialog extends Dialog {

    private OnButtonClickListener onButtonClickListener;

    private DialogDeleteUserBinding binding;
    private String title = "";
    private String content = "";
    private String leftBtnStr = "";
    private String rightBtnStr = "";

    public DeleteUserDialog(Context context) {
        super(context, com.fenghuajueli.libbasecoreui.R.style.StyleBaseDialog);
    }

    public DeleteUserDialog(Context context, String title, String content, String leftBtnStr, String rightBtnStr) {
        super(context, com.fenghuajueli.libbasecoreui.R.style.StyleBaseDialog);
        this.title = title;
        this.content = content;
        this.leftBtnStr = leftBtnStr;
        this.rightBtnStr = rightBtnStr;
    }

    public void setOnButtonClickListener(OnButtonClickListener onButtonClickListener) {
        this.onButtonClickListener = onButtonClickListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DialogDeleteUserBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width = SizeUtils.dp2px(310);
        getWindow().setAttributes(layoutParams);

        if (!title.isEmpty()) {
            binding.textView.setText(title);
        }

        if (!content.isEmpty()) {
            binding.textView2.setText(content);
        }

        if (!leftBtnStr.isEmpty()) {
            binding.btnCancel.setText(leftBtnStr);
        }

        if (!rightBtnStr.isEmpty()) {
            binding.btnConfirm.setText(rightBtnStr);
        }

        binding.btnCancel.setOnClickListener(v -> {
            if (onButtonClickListener != null) {
                onButtonClickListener.onLeftButtonClick();
            }
            dismiss();
        });

        binding.btnConfirm.setOnClickListener(v -> {
            if (onButtonClickListener != null) {
                onButtonClickListener.onRightButtonClick();
            }
            dismiss();
        });
    }


    public interface OnButtonClickListener {

        void onLeftButtonClick();

        void onRightButtonClick();
    }

}
